<h2 class="non lower">Batch Edit Descriptions &nbsp;&nbsp;&nbsp;<small>Click on labels below to edit work descriptions.</small> </h2>

<div class="scrollx scrolly fileHeight"> <!-- original values -->
  <h3> <b>Changes will be applied to: (<%= @form.names.size %> works) </b></h3>
   <%= @form.names.join(", ").html_safe %>
</div> <!-- /original values -->

<div >
  <h3> Descriptions:</h3>

    <ul class="nav nav-tabs">
      <li id="edit_descriptions_link" class="active"><a href="#descriptions_display" data-toggle="tab"><i class="glyphicon glyphicon-tags"></i> Descriptions</a></li>
      <li id="edit_permissions_link"><a href="#permissions_display" data-toggle="tab"><i class="glyphicon glyphicon-lock"></i> Permissions</a></li>
    </ul>
    <div class="tab-content">
      <div class="tab-pane active" id="descriptions_display">
        <% @form.terms.each do |term| %>
          <div class="row">
            <%= simple_form_for @form.model,
                                url: batch_edits_path,
                                method: :put,
                                remote: true,
                                builder: Sufia::FormBuilder,
                                html: { id: "form_#{term.to_s}",
                                        class: "ajax-form" },
                                data: { model: @form.model_name.param_key } do |f| %>
              <div class="col-xs-12 col-sm-4">
                <a class="accordion-toggle grey glyphicon-chevron-right-helper collapsed" data-toggle="collapse" href="#collapse_<%= term %>" id="expand_link_<%=term.to_s%>">
                  <%= f.input_label term %> <span class="chevron"></span>
                </a>
              </div>
              <div id="collapse_<%= term %>" class="collapse scrolly col-xs-12 col-sm-7">
                  <%= hidden_field_tag('update_type', 'update') %>
                  <%= hidden_field_tag('key', term.to_s) %>
                  <%# TODO we don't need to show required %>
                  <%= render_edit_field_partial(term, f: f) %>
                  <div>
                    <%= f.submit "Save changes", class: 'btn btn-primary field-save updates-batches' , id: "#{term.to_s}_save" %>
                    <a class="btn btn-default" data-toggle="collapse" data-parent="#row_<%= term.to_s %>" href="#collapse_<%= term.to_s %>">Cancel </a>
                    <div class="status fleft"></div>
                  </div>
              </div>
            <% end %>
          </div>
        <% end %>
      </div><!-- #descriptions_display -->

      <div id="permissions_display" class="tab-pane">
        <%= simple_form_for @form.model, url: batch_edits_path, method: :put, remote: true, html: { id: "form_permissions", class: "ajax-form"} do |f| %>
           <%= hidden_field_tag('update_type', 'update') %>
           <%= hidden_field_tag('key', 'permissions') %>
           <%= render "curation_concerns/file_sets/permission_form", f: f %>
         <div class="row">
            <%= f.submit "Save changes", class: 'btn btn-primary updates-batches', id: 'permissions_save' %>
            <div id="status_permissions" class="status fleft"></div>
         </div>
       <% end %>
     </div>
   </div> <!-- .tab-content -->

<!-- Ajax call to clear the batch before page uload. -->
<%= button_to "Clear Batch", { controller: :batch_edits, action: :clear }, form_class: 'hidden', remote: true, id: 'clear_batch' %>

</div><!-- descriptions_display -->
